<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!--Bmap-->

        <style type="text/css">
            body,
            html {
                width: 100%;
                height: 100%;
                margin: 0;
                font-family: "微软雅黑";
                font-size: 14px;
            }

            #l-map {
                height: 300px;
                width: 100%;
            }

            #r-result {
                width: 100%;
            }

            .tangram-suggestion-main {
                z-index: 9999999999;
            }
        </style>
        <script src="res/jquery-3.4.1.min.js" type="text/javascript" content="utf-8"></script>
        <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=sz2me2dzwHo84TpO4F6VVY33fkpebBLD"></script>

    </head>
    <body class="hold-transition">
        <div id="app">
            <!--这里是页面中的头部分-->
            <div class="content-header">
                <h1>首页<small>公司分布图</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>公司分布图</el-breadcrumb-item>

                </el-breadcrumb>
            </div>
            <!--这里是容器的开始,可以存放页面-->
            <div class="app-container">
                <template>
                    <el-tabs v-model="activeName" @tab-click="handleClick">

                        <!--分布图页面-->
                        <el-tab-pane label="分布图" name="first">
                            <iframe name="right" class="el-main" src="../bmaps/map.html" width="100%" height="580px">

                            </iframe>
                        </el-tab-pane>


                        <!--详细信息页面-->
                        <el-tab-pane label="详细信息" name="second">
                            <div class="filter-container">
                                <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                            </div>
                            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                                <el-table-column type="index" align="center" label="序号"></el-table-column>
                                <el-table-column prop="addressName" label="公司地址" align="center"></el-table-column>
                                <el-table-column prop="lng" label="所在经度" align="center"></el-table-column>
                                <el-table-column prop="lat" label="所在纬度" align="center"></el-table-column>
                                <el-table-column label="操作" align="center">
                                    <template slot-scope="scope">
                                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <div class="pagination-container">
                                <el-pagination
                                        class="pagiantion"
                                        @current-change="handleCurrentChange"
                                        :current-page="pagination.currentPage"
                                        :page-size="pagination.pageSize"
                                        layout="total, prev, pager, next, jumper"
                                        :total="pagination.total">
                                </el-pagination>
                            </div>

                            <!-- 新增标签弹层 -->
                            <div class="add-form">
                                <el-dialog title="新增地址" :visible.sync="dialogFormVisible" @opened="createMap">
                                   <div class="filter-container">
                                        <el-input id="suggestId"  name="address_detail" placeholder="请输入要查询的地址" v-model="address_detail" style="width: 400px;" class="filter-item"></el-input>
                                        <el-button @click="handleAdd()" class="butT">确定添加</el-button>
                                       <!--提示下拉框-->
                                       <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                                       <!--隐藏-->
                                       <div class="" hidden >
                                           地址:<input type="text" id="address" value="百度" readonly="readonly" placeholder="请输入地址" />
                                       </div>
                                    </div>
                                    <div id="l-map"></div>


                                </el-dialog>
                            </div>


                        </el-tab-pane>

                    </el-tabs>
                </template>
            </div>
        </div>
    </body>

    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName: 'first',//选项卡
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:100,//总记录数
					  queryString:null//查询条件
				},

				dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit:false,//编辑表单是否可见
                address_detail:'' //地址信息



            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                //调用分页查询方法完成分页查询
                this.findPage();
            },
            mounted(){

            },
            methods: {

               //BMap地图
                createMap(){
                    // 百度地图API功能
                    function G(id) {
                        return document.getElementById(id);
                    }

                    var map = new BMap.Map("l-map");
                    // 初始化地图,设置城市和地图级别。
                    map.centerAndZoom("北京", 12);
                    //建立一个自动完成的对象
                    var ac = new BMap.Autocomplete({
                        "input": "suggestId",
                        "location": map
                    });
                    //鼠标放在下拉列表上的事件
                    ac.addEventListener("onhighlight", function(e) {
                        var str = "";
                        var _value = e.fromitem.value;
                        var value = "";
                        if (e.fromitem.index > -1) {
                            value = _value.province + _value.city + _value.district + _value.street + _value.business;
                        }
                        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

                        value = "";
                        if (e.toitem.index > -1) {
                            _value = e.toitem.value;
                            value = _value.province + _value.city + _value.district + _value.street + _value.business;
                        }
                        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
                        G("searchResultPanel").innerHTML = str;
                    });

                    var myValue;
                    //鼠标点击下拉列表后的事件
                    ac.addEventListener("onconfirm", function(e) {
                        var _value = e.item.value;
                        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
                        G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
                        setPlace();
                    });

                    function setPlace() {
                        //清除地图上所有覆盖物
                        map.clearOverlays();

                        function myFun() {
                            //获取第一个智能搜索的结果
                            var pp = local.getResults().getPoi(0).point;
                            // 获取搜索结果的详细地址
                            window.alert(local.getResults().getPoi(0).address);

                            let address = local.getResults().getPoi(0).address;


                            // 将获取到的地址填充到表单
                            window.document.getElementById("address").value = address;

                            map.centerAndZoom(pp, 18);

                            // 创建标注
                            var marker = new BMap.Marker(pp);
                            //添加标注
                            map.addOverlay(marker);
                            //跳动的动画
                            marker.setAnimation(BMAP_ANIMATION_BOUNCE);
                            //启用滚轮放大缩小
                            map.enableScrollWheelZoom();

                        }
                        //智能搜索
                        var local = new BMap.LocalSearch(map, {
                            onSearchComplete: myFun
                        });
                        local.search(myValue);

                    }
                },

                handleClick(tab) {
                    if (tab.name == "first") {
                        this.isChildUpdate1 = true;
                        this.isChildUpdate2 = false;
                    } else if (tab.name == "second") {
                        this.isChildUpdate1 = false;
                        this.isChildUpdate2 = true;
                    }
                },

                //添加
                handleAdd() {
                    this.address_detail = window.document.getElementById("address").value;
                    //var address = encodeURI(encodeURI(this.address_detail));
                   // alert(this.address_detail);
                            //发送ajax请求，将数据提交到Controller
                            axios.post("/address/add.do?addressName="+this.address_detail).then((res) => {
                                if (res.data.flag) {
                                    //处理成功
                                    this.$message({
                                        type: 'success',
                                        message: res.data.message
                                    });
                                    //关闭新增窗口
                                    this.dialogFormVisible = false;
                                    //分页查询
                                    this.findPage();
                                } else {
                                    //处理失败
                                    this.$message.error(res.data.message);
                                }
                            });


                },
                //分页查询
                findPage() {
                    var param = {
                        currentPage: this.pagination.currentPage,
                        pageSize: this.pagination.pageSize,
                        queryString: this.pagination.queryString
                    };

                    //发送ajax请求，进行分页查询
                    axios.post("/address/findPage.do", param).then((res) => {
                        this.pagination.total = res.data.total;
                        this.dataList = res.data.rows;
                    });

                },
                // 重置表单
                resetForm() {
                    this.formData = {};
                },
                // 弹出添加窗口
                handleCreate() {
                    this.resetForm();
                    //将添加窗口展示出来
                    this.dialogFormVisible = true;
                },

                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;//指定最新的页码
                    this.findPage();
                },

               /* showMessage(r) {
                    if (r == 'Error: Request failed with status code 403') {
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    } else {
                        this.$message.error('未知错误');
                        return;
                    }
                },*/

                // 删除
                handleDelete(row) {
                    //弹出确认框
                    this.$confirm('你确定要删除当前数据吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //发送ajax请求，将id提交到Controller
                        axios.get("/address/delete.do?id=" + row.id).then((res) => {
                            if (res.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: res.data.message
                                });
                                this.findPage();
                            } else {
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).catch((r) => {
                            this.showMessage(r);
                        });
                    }).catch(() => {
                        this.$message("已取消");
                    });
                }

            }

        })
    </script>


</html>
